﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

namespace PBDesk.AutoGen.AutoEnums
{
    public class EnumCreationList : ConfigurationSection
    {
        [ConfigurationProperty("enumItems")]
        public EnumItemColl EnumList
        {
            get
            {
                return this["enumItems"] as EnumItemColl;
            }
        }

        public static EnumCreationList GetList()
        {
            var s = ConfigurationManager.GetSection("enumConfigs");
            return ConfigurationManager.GetSection("enumConfigs") as EnumCreationList;
        }

        

    }

    public class EnumItem : ConfigurationElement
    {
        [ConfigurationProperty("enumName", IsRequired = true)]
        public string EnumName
        {
            get
            {
                return (string)this["enumName"];
            }
            set
            {
                this["enumName"] = value;
            }
        }

        [ConfigurationProperty("valueColumn", IsRequired = true)]
        public string ValueColumn
        {
            get
            {
                return (string)this["valueColumn"];
            }
            set
            {
                this["valueColumn"] = value;
            }
        }

        [ConfigurationProperty("tableName", IsRequired = true)]
        public string TableName
        {
            get
            {
                return (string)this["tableName"];
            }
            set
            {
                this["tableName"] = value;
            }
        }

        [ConfigurationProperty("literalcolumn", IsRequired = true)]
        public string Literalcolumn
        {
            get
            {
                return (string)this["literalcolumn"];
            }
            set
            {
                this["literalcolumn"] = value;
            }
        }

        [ConfigurationProperty("enumType", IsRequired = true)]
        public string EnumType
        {
            get
            {
                return (string)this["enumType"];
            }
            set
            {
                this["enumType"] = value;
            }
        }
    }

    public class EnumItemColl : ConfigurationElementCollection
    {
        protected override ConfigurationElement CreateNewElement()
        {
            return new EnumItem();
        }

        protected override object GetElementKey(ConfigurationElement element)
        {
            return ((EnumItem)element).EnumName;
        }
        public EnumItem this[int index]
        {
            get
            {
                return base.BaseGet(index) as EnumItem;
            }
            set
            {
                if (base.BaseGet(index) != null)
                {
                    base.BaseRemoveAt(index);
                }
                this.BaseAdd(index, value);
            }
        }
    }
}
